home *** CD-ROM | disk | FTP | other *** search
/ ftp.cs.arizona.edu / ftp.cs.arizona.edu.tar / ftp.cs.arizona.edu / icon / newsgrp / group98a.txt / 000052_icon-group-sender _Tue Feb 24 13:03:15 1998.msg < prev    next >
Internet Message Format  |  2000-09-20  |  3KB

  1. Return-Path: <icon-group-sender>
  2. Received: from kingfisher.CS.Arizona.EDU (kingfisher.CS.Arizona.EDU [192.12.69.239])
  3.     by baskerville.CS.Arizona.EDU (8.8.7/8.8.7) with SMTP id NAA05023
  4.     for <icon-group-addresses@baskerville.CS.Arizona.EDU>; Tue, 24 Feb 1998 13:03:11 -0700 (MST)
  5. Received: by kingfisher.CS.Arizona.EDU (5.65v4.0/1.1.8.2/08Nov94-0446PM)
  6.     id AA29989; Tue, 24 Feb 1998 13:03:11 -0700
  7. Date: Tue, 24 Feb 1998 08:03:36 -0800
  8. From: kwalker@sfo.harbinger.com (Ken Walker)
  9. Message-Id: <199802241603.IAA12817@varda.premenos.com>
  10. To: icon-group@optima.CS.Arizona.EDU, sunyd21@aol.com, mr2r@erols.com
  11. Subject: Re: help with icon programing
  12. Mime-Version: 1.0
  13. Content-Type: text/plain; charset=us-ascii
  14. Content-Transfer-Encoding: 7bit
  15. Content-Md5: F7DEN7W/z/Z0i2i1ArEtDw==
  16. Errors-To: icon-group-errors@optima.CS.Arizona.EDU
  17. Status: RO
  18. Content-Length: 1833
  19.  
  20. > Date: Tue, 24 Feb 1998 01:56:29 -0500
  21. > From: Adnan Khan <mr2r@erols.com>
  22. >    I am new with this language and I have two questions.   I am trying
  23. > to intialize a character in icon language and i don't know how to do
  24. > it.  Could you please tell me how to intilize something as a character.
  25. > Second, I am checking if two things or same or not by using an 'if'
  26. > statement. and... my project reads one character and checks if it is '0'
  27. > (zero) or not.  As long as the character which is read in from the file
  28. > is an integer the program runs fine, but when it reads a non-integer
  29. > charcter from the file it gives me an error msg. of something like type
  30. > mismatch or something.   My first question relates to the same thing.  I
  31. > want to declare that the thing read from the file is a character and not
  32. > an integer and then I want to compare them.
  33.  
  34. Icon has no character data type; it has only character sets and character
  35. strings. The function call, reads(file, 1), returns a character string
  36. of length one. Icon automatically converts been integers and character
  37. strings when it can. It sounds like you are using the integer comparison
  38. operator. This works okay when you read a digit because the digit
  39. is converted to an integer before the comparison, but for a non-digit
  40. character which cannot be converted, it produces an error. You need to
  41. use the string comparison operator:
  42.  
  43.    if chr == "0" then ...
  44.    
  45. Note that Icon variable declarations contain no type information. In Icon,
  46. it is values not variables that have type. Any variable can have a value
  47. of any type. If you want to determine if a string can be converted to an
  48. integer, you can try an explicit conversion and see if it succeeds or
  49. fails:
  50.  
  51.    if integer(str) then ... 
  52.    
  53. Ken Walker, kwalker@sfo.harbinger.com
  54. Harbinger Coporation, Concord, Ca. 94520
  55.